package com.bootcamp.javase.compare.testCat2;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @program: CompareCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-07 21:58
 **/

public class CalcLifeDay {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        System.out.print("按此格式输入出生年月日：yyyy-MM-dd: ");
        String sBirthDate = sc.nextLine().trim();
        Date currentDate = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println("当前年月日为： "+ format.format(currentDate));
        Date birthDate = format.parse(sBirthDate);
        int dayPassed = (int)((currentDate.getTime()-birthDate.getTime())/(1000L*60*60*24));
        System.out.println("到今天经过了 "+dayPassed+" 天");
    }
}
